package com.boco.fznq.home;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.boco.fznq.R;
import com.boco.fznq.model.BannerModel;
import com.boco.fznq.webview.MyWebviewActivity;
import com.culiu.core.fonts.CustomTextView;
import com.culiu.core.utils.view.ViewUtils;
import com.culiu.core.widget.CustomImageView;

import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by jiangcheng on 2016/12/13.
 */

public class HomeRvAdapter extends RecyclerView.Adapter<HomeRvAdapter.HomeViewHolder> {


    private Context mContext;

    private List<NewsBean.News> mDatas;


    public HomeRvAdapter(Context context) {
        this.mContext = context;
    }

    public void setDatas(List<NewsBean.News> newsList) {
        mDatas = newsList;
        notifyDataSetChanged();
    }



    @Override
    public HomeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_home_news, null);
        return new HomeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(HomeViewHolder holder, int position) {
        final NewsBean.News news = mDatas.get(position);
        if (news == null) {
            return;
        }

        holder.newsTitle.setText(news.getTitle());
        holder.newsDesc.setText(news.getDesc());
        holder.newsDate.setText(news.getDate());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyWebviewActivity.startMyWebView((Activity) mContext, news.getDetailUrl());
            }
        });
    }


    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    public class HomeViewHolder extends ViewHolder {

        CustomTextView newsTitle;
        CustomTextView newsDesc;
        CustomTextView newsDate;

        public HomeViewHolder(View itemView) {
            super(itemView);
            newsDesc = (CustomTextView) itemView.findViewById(R.id.news_desc);
            newsTitle = (CustomTextView) itemView.findViewById(R.id.news_title);
            newsDate = (CustomTextView) itemView.findViewById(R.id.news_date);
        }
    }
}
